<?php
class KD_Helper{
  public static function arraySqlFormat($inputArr, $dbms='mysql'){
    $outArr = array();
    $errMsg = array();
    foreach($inputArr as $key=>$item){
      if( is_array($item) == false ){ $errMsg[$key] =  'this item type not is array';}
      else{

        $outArr[$key] = array();
        $outItem = & $outArr[$key];

        foreach($item as $subKey=>$subItem){
          if( is_string($subItem) ){
            if($dbms == 'mysql'){
              $outItem["`$subKey`"] = "'$subItem'";
            }
            elseif($dbms == 'sqlite'){
              $outItem[$subKey] = "'$subItem'";
            }
          }else{
            if( is_numeric($subItem) ){
              $outItem[$subKey] = $subItem;
            }else{
              $errMsg[$key] = array();
              $errMsg[$key][$subKey] = 'this item type not is numeric or string';
            }
          }
        }
      }
    }
    return array( 'output'=>$outArr, 'errMsg'=>$errMsg);
  }

  public static function sqlFormat($inputSql, $dbms='other'){
    $sql_left_delimiter ='`';
    sql_right_delimiter ='`';
    if($dbms == 'mysql'){
      $return $inputSql;
    }
    elseif($dbms == 'other'){
      $outputSql = ereg_replace('`', '', $inputSql);
      return $outputSql;
    }
    else{
      $outputSql = ereg_replace('`', '', $inputSql);
      return $outputSql;
    }
  }
}
